home *** CD-ROM | disk | FTP | other *** search
/ CD-ROM Today - The Disc! 5 / CD-ROM Today - The Disc (Issue 5)(November 1994).ISO / mac / Mac shareware / Education / RLaB / rlib / set.r < prev    next >
Text File  |  1994-09-21  |  745b  |  40 lines

  1. //-------------------------------------------------------------------//
  2. //  set
  3.  
  4. //  Syntax:    set ( A )
  5.  
  6. //  Description:
  7.  
  8. //  The set function takes an vector argument (A), and returns a
  9. //  vector that is sorted in ascending order, and has no duplicate
  10. //  values. 
  11.  
  12. //  See Also: complement, intersection, union
  13. //-------------------------------------------------------------------//
  14.  
  15. set = function ( A )
  16. {
  17.   local (a, i, j, s, tmp)
  18.  
  19.   if (min (size (A)) != 1) {
  20.     error ("set: requires vector argument");
  21.   }
  22.  
  23.   i = j = 1;
  24.   a = sort (A).val;
  25.   while (i <= a.n)
  26.   {
  27.     tmp = find (a[i] == a);
  28.     if (tmp.n > 1) 
  29.     {
  30.       s[j] = a[tmp[1]];
  31.       i = i + tmp.n;
  32.     else
  33.       s[j] = a[tmp];
  34.       i++;
  35.     }
  36.     j++;
  37.   }
  38.   return s
  39. };
  40.